#pragma once
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>

namespace myPriority_Queue
{
	template<class T, class Container = std::vector<T>, class Compare = std::less<T>>
	class priority_queue
	{
	public:
		void AdjustUp(size_t child)
		{
			Compare cmp;
			size_t parent = (child - 1) / 2;
			while (child > 0)
			{
				if (cmp(_con[parent], _con[child]))
				{
					std::swap(_con[parent], _con[child]);
					child = parent;
					parent = (child - 1) / 2;
				}
				else
					break;
			}
		}

		void AdjustDown(size_t parent)
		{
			Compare cmp;
			size_t child = parent * 2 + 1;
			if (child + 1 < _con.size() && cmp(_con[child], _con[child + 1]))
				child++;
			while (child < _con.size())
			{
				if (cmp(_con[parent], _con[child]))
				{
					std::swap(_con[parent], _con[child]);
					parent = child;
					child = parent * 2 + 1;
				}
				else
					break;
			}
		}

		void pop()
		{
			std::swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();
			AdjustDown(0);
		}

		void push(const T& val)
		{
			_con.push_back(val);
			AdjustUp(_con.size() - 1);
		}

		bool empty()
		{
			return _con.empty();
		}

		const T& top()
		{
			return _con[0];
		}

	private:
		Container _con;
	};
}